package com.cn.wanxi.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.UserService;
import com.cn.wanxi.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/getCount")
public class UserGetCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       0.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//      1.取得页面的值
        String username = req.getParameter("username");
        String phone = req.getParameter("phone");

//      2.封装数据
        UserModel userModel = new UserModel();
        userModel.setUsername(username);
        userModel.setPhone(phone);

//      3.调用逻辑层
        UserService userService = new UserServiceImpl();
//      4.得到返回结果
        ResultModel resultModel = userService.getCount(userModel);
//      5.返回结果集
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
